package com.sfpay.coreplatform.account.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sfpay.coreplatform.account.common.AccountResponseCode;
import com.sfpay.coreplatform.account.persistence.dao.IAccountDao;
import com.sfpay.coreplatform.account.service.IAccountInfoQueryService;
import com.sfpay.coreplatform.account.service.exception.AccountServiceException;
import com.sfpay.coreplatform.account.valueobject.tmo.AccountVO;
import com.sfpay.framework.common.util.AssertUtils;

@Service
public class AccountInfoQueryServiceImpl implements IAccountInfoQueryService {
	
	
	private static final Logger logger = LoggerFactory.getLogger(AccountInfoQueryServiceImpl.class);

	@Resource
	private IAccountDao accountDao;
	

	/**
	 * 根据账户编号查找账户信息
	 *
	 * 方法说明：
	 *
	 * @param accNo
	 * @return
	 * @throws AccountServiceException
	 *
	 * @author 299015 彭阳
	 */
	public AccountVO findAccountInfoByAccountNo(Long accNo) throws AccountServiceException{
		logger.debug("findAccountInfoByAccountNo(Long) - start"); //$NON-NLS-1$
		try{
			AssertUtils.notNull(accNo);

			AccountVO returnAccountVO = accountDao.selectByAccountNo(accNo);
			return  returnAccountVO;

		}catch (Exception e) {
			logger.error("findAccountInfoByAccountNo, accNo is " + accNo ,e);
			throw new AccountServiceException(AccountResponseCode.ACCOUNT_QUERY_EXCEPTION, "DB Exception", e);
		}
	}

	/**
	 * 
	 *
	 * 方法说明：根据账户编号查找账户信息，适用于小量获取数据。
	 *
	 * @param accNoList 账户编号组成的LIST
	 * @return  Map<String,AccountVO>:
	 * 				String: 账户编号
	 * 				AccountVO：账户信息
	 * @throws AccountServiceException
	 *
	 * @author 299015 彭阳
	 */
	public Map<Long,AccountVO> findAccountInfo(List<Long> accNoList) throws AccountServiceException{
		logger.debug("findAccountInfo(List<Long>) - start"); //$NON-NLS-1$
		try{
			AssertUtils.notEmpty(accNoList);

			Map<Long,AccountVO> map = new HashMap<Long,AccountVO>();
			for (Long accountNo : accNoList) {
				AccountVO accountVO = accountDao.selectByAccountNo(accountNo);
				map.put(accountNo, accountVO);
			}

			logger.debug("findAccountInfo(List<Long>) - end"); //$NON-NLS-1$
			return map;
		}catch (Exception e) {
			logger.error("findAccountInfo, accNoList is " + accNoList,e);
			throw new AccountServiceException(AccountResponseCode.ACCOUNT_QUERY_EXCEPTION, "DB Exception", e);
		}
	}

}
